﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;

namespace QUANLYKHACHSAN_N4
{
    public partial class frmQuanLyPhieuThu : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public frmQuanLyPhieuThu()
        {
            InitializeComponent();
        }

        TaiKhoan_Info tk;
        private void frmQuanLyPhieuThu_Load(object sender, EventArgs e)
        {
            cbChoose.SelectedIndex = 0;
            XuLyDataGridView.Style(dgrDanhSach);
            dgrDanhSach.DataSource = PhieuThu_Info.GetAll();
            tk = (this.MdiParent as frmFormMain).tk;
        }

       

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (dgrDanhSach.SelectedRows.Count == 0)
            {
                DgResul.ShowDiag("Chọn Phiếu Thu cần xóa sau đó nhấn xóa");
                return;
            }
            else
            {
                if (DgResul.ShowDiag("Bạn có muốn xóa những phiếu được chọn", true))
                {
                    foreach (DataGridViewRow r in dgrDanhSach.SelectedRows)
                        PhieuThu_Info.Delete(r.Cells["MAPHIEU"].Value.ToString());
                    this.OnLoad(null);
                    DgResul.ShowDiag("Đã xóa những phiếu được chọn");
                }
            }
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (dgrDanhSach.SelectedRows.Count == 0)
            {
                DgResul.ShowDiag("Chọn Phiếu Thu cần sửa sau đó nhấn sửa");
                return;
            }
            dgrDanhSach_CellMouseDoubleClick(null, null);
        }

        private void btnInAn_Click(object sender, EventArgs e)
        {
            if (dgrDanhSach.SelectedRows.Count == 0)
            {
                DgResul.ShowDiag("Chọn Phiếu Thu cần in sau đó nhấn in");
                return;
            }
            try
            {

                frmFormMain frm = MdiParent as frmFormMain;
                frm.pr = new frmPrint();
                DuLieuRP.SetKhungPrint(frm.pr, "ds_KhachHang_GetID", frm.pr.KhachHangBindingSource);
                frm.pr.rpViewer.LocalReport.ReportEmbeddedResource = "QUANLYKHACHSAN_N4.REPORT.rpThongTinPhieuThu.rdlc";
                frm.pr.PhieuThu_GetByIDBindingSource.DataSource = PhieuThu_Info.DsGetByID(dgrDanhSach.CurrentRow.Cells["MAPHIEU"].Value.ToString()).Tables[0];
                frm.pr.rpViewer.RefreshReport();
                frm.pr.Text = "PHIẾU THU TIỀN";
                frm.ShowPrint();
            }
            catch (Exception)
            {

            }
        }

        private void btnThemPhieuThu_Click(object sender, EventArgs e)
        {
            frmChiTietPhieuThu frm = new frmChiTietPhieuThu();
            frm.tk = tk;
            frm.ShowDialog();
            if (frm.acction)
                frmQuanLyPhieuThu_Load(null, null);
        }

        private void dgrDanhSach_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                DataGridViewRow r = dgrDanhSach.CurrentRow;
                frmChiTietPhieuThu frm = new frmChiTietPhieuThu(PhieuThu_Info.GetByID(r.Cells["MAPHIEU"].Value.ToString())[0]);
                frm.tk = tk;
                frm.ShowDialog();
                if (frm.acction)
                    frmQuanLyPhieuThu_Load(null, null);
            }
            catch (Exception)
            {

            }
        }



    }
}
